﻿Ext.define('app.prm.synth.Index', {
    extend: 'Ext.panel.Panel',
    border: false,
    tbar: [],
    requires: ['app.prm.synth.SynthController', 'app.prm.synth.SynthModel'],
    controller: 'synth',
    viewModel: {
        type: 'synthmodel'
    },
    bodyStyle: 'padding:5px',
    autoScroll: true,
    initComponent: function () {
        var me = this;

        me.projectId = me.paramsId;
        me.items = [];
        me.tbar = [{
            text: '新增工艺路线',
            bind: {
                hidden: '{!hasSynthAdd}'
            },
            icon: '/Content/images/add.png',
            handler: 'onAddSynth'
        },
        {
            text: '刷新', glyph: 0xf021,
            handler: function () { me.reshPage(); }
        }
        ,'*工艺双击可放大'
        ];
        me.callParent();
    },
    reshPage: function () {
        var me = this;
        me.removeAll(true);
        App.AjaxGet('/api/services/app/synthesis/GetSynthesis?projectId=' + me.projectId, function (data) {
            var json = data.result;
            for (var i = 0; i < json.length; i++) {
                var record = json[i];
                var panel = Ext.create("app.prm.synth.SynthList", { record: record });
                panel.on("editsuccess", me.reshPage, me);
                panel.on("removesuccess", me.reshPage, me);
                me.add(panel);
            }
        });
    },
    listeners: {
        afterrender: 'onInit'
    }
})